package com.shoppingmall.controller;


import com.shoppingmall.commons.PageParam;
import com.shoppingmall.commons.Result;
import com.shoppingmall.model.Goods;
import com.shoppingmall.service.GoodsService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @GetMapping(value = "/queryGoods")
    public List<Goods> queryGood(){
        System.out.println(goodsService.queryGoods(0));
        return goodsService.queryGoods(0);
    }
    @GetMapping(value = "/queryGoodById")
    public Goods queryGoodById(int goods_id){
       return goodsService.queryGoodById(goods_id);
    }
    @PostMapping(value = "/addGoods")
    public void addGoods(@RequestBody Goods goods){
        goodsService.addGoods(goods);
    }
    @PostMapping(value = "/updateGoods")
    public void updateGoods(@RequestBody Goods goods){
        goodsService.updateGoods(goods);
    }
    @GetMapping("/queryCommentByGoodsId")
    public Map<String,Object> queryCommentByGoodsId(int goods_id, PageParam pageParam){
        return goodsService.queryCommentByGoodsId(goods_id,pageParam);
    }

    @PostMapping(value = "/delGoods")
    public void delGoods(int...goods_ids){
        goodsService.delGoods(goods_ids);
    }
    @PostMapping(value = "/queryGoodsByName")
    public List<Goods> queryGoodsByName(String goods_name){
        return goodsService.queryGoodsByName(goods_name);
    }
    @PostMapping(value = "queryGoodsByKind")
    public List<Goods> queryGoodsByKind(int goods_kind){
        return goodsService.queryGoodsByKind(goods_kind);
    }
    //管理端
    @GetMapping(value = "/mangerqueryGood")
    public List<Goods> mangerqueryGood(int goods_display){
        return goodsService.mangerqueryGood(goods_display);
    }
    @PostMapping(value = "/updatemangerGoods")
    public Result updatemangerGoods(int goods_display, int goods_id){
        goodsService.updatemangerGoods(goods_display,goods_id);
        String message=goods_display==0?"上架":"下架";
        return Result.success(message+"成功");
    }
}

